<?php
header('Content-Type: application/json');
Header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE');
header("Access-Control-Allow-Headers: Content-Type");
header('Access-Control-Allow-Origin:*');   //跨域

require './mysql_init.php';

//删除session
function delete_session($pdo,$session_id){
    try {
        // 准备删除语句并绑定参数
        $query = "delete from session where session_id= ?";
        $statement = $pdo->prepare($query);
        $statement->bindParam(1, $session_id);
        // 执行操作
        $statement->execute();
        return 1;
        // echo "Data inserted successfully.";
    } catch (PDOException $e) {
        // echo "Error inserting data: " . $e->getMessage();
        return 0;
    }
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {      //判断是否是post请求
    $response = array(
        'status' => 0,
        'message' => '是post请求'
    );

    $json=file_get_contents('php://input');  //获取post请求中的原始数据
    $post_json=json_decode($json,true);       //把原始数据转化成json
    $session_id=$post_json['session_id'];    //获取session_id
    $i=delete_session($pdo,$session_id);
    if($i===1){
        $response = array(
            'status' => 1,
            'message' => 'session_id删除成功'
        );
    }else{
        $response = array(
            'status' => 0,
            'message' => 'session_id删除失败'
        );
    }
    echo json_encode($response);
}else{
    $response = array(
        'status' => 0,
        'message' => '不是post请求'
    );
    echo json_encode($response);
}

?>